import config from "../config"
import { FetchAPI, LoginUser, SimpleUser } from "../interfaces"
import { ERRORS } from "../utils/common"
import { getAllUsers } from "../utils/users"

/** 获取登录用户信息 */
export const user_info: FetchAPI<any, LoginUser> = async (__, { loginUser }) => {
  return {
      success: true,
      data: loginUser,
  }
}

export const user_all: FetchAPI<any, SimpleUser[]> = async (__, { req }) => {
  const users = await getAllUsers(req)
  if (users) {
    return {
      success: true,
      data: users
    }
  } else {
    return {
      error: ERRORS.NO_USERS,
    }
  }
}
